"use strict";

module.exports = {
    up: async (queryInterface, Sequelize) => {
        /**
         * Add altering commands here.
         *
         * Example:
         * await queryInterface.createTable('users', { id: Sequelize.INTEGER });
         */
        try {


            await queryInterface.createTable("users", {
                id: {
                    type: Sequelize.INTEGER(11).UNSIGNED,
                    allowNull: false,
                    primaryKey: true,
                    autoIncrement: true,
                    comment: "用户 ID",
                },
                email: {
                    type: Sequelize.STRING(255),
                    allowNull: false,
                    comment: "邮箱",
                },
                password: {
                    type: Sequelize.STRING(100),
                    allowNull: false,
                    comment: "密码",
                },
                nickname: {
                    type: Sequelize.STRING(100),
                    allowNull: true,
                    comment: "昵称",
                },
                introduce: {
                    type: Sequelize.STRING(255),
                    allowNull: false,
                    defaultValue: "",
                    comment: "个人介绍",
                },
                avatar: {
                    type: Sequelize.STRING(255),
                    allowNull: true,
                    comment: "头像",
                },
                pendant: {
                    type: Sequelize.STRING(255),
                    allowNull: true,
                    comment: "头像框",
                },
                gender: {
                    type: Sequelize.INTEGER(1).UNSIGNED,
                    allowNull: false,
                    defaultValue: 0,
                    comment: "性别 0:保密 1:男 2:女",
                },
                status: {
                    type: Sequelize.INTEGER(1).UNSIGNED,
                    allowNull: false,
                    defaultValue: 0,
                    comment: "用户状态：0 正常 1 禁用 2 审核中 3 审核拒绝 4 审核忽略",
                },
                fans_count: {
                    type: Sequelize.INTEGER(10).UNSIGNED,
                    allowNull: false,
                    defaultValue: 0,
                    comment: "粉丝数",
                },
                follow_count: {
                    type: Sequelize.INTEGER(10).UNSIGNED,
                    allowNull: false,
                    defaultValue: 0,
                    comment: "关注数",
                },
                liked_count: {
                    type: Sequelize.INTEGER(10).UNSIGNED,
                    allowNull: false,
                    defaultValue: 0,
                    comment: "点赞数",
                },
                login_at: {
                    type: Sequelize.DATE,
                    allowNull: true,
                    comment: "最后登录时间",
                },
                created_at: {
                    type: Sequelize.DATE,
                    allowNull: true,
                    comment: "创建时间",
                },
            }, {
                comment: "用户表",
            });


            await queryInterface.addIndex("users", [ "nickname" ], {
                unique: true,
                name: "用户昵称唯一",
            });
            await queryInterface.addIndex("users", [ "email" ], {
                unique: true,
                name: "用户邮箱唯一",
            });


        } catch (error) {
            await queryInterface.dropTable("users");
            throw error;
        }
    },

    down: async queryInterface => {
        /**
         * Add reverting commands here.
         *
         * Example:
         * await queryInterface.dropTable('users');
         */
        await queryInterface.dropTable("users");
    },
};
